package Satellites;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Satellite {

	private String satelliteName;
	private File directory;
	private String line1;
	private String line2;
	private String line3;
	private Orbit orbit;
	private boolean isVisible;

	public Satellite(String satelliteName, File directory){
		this.satelliteName=satelliteName;
		this.directory= directory;
		isVisible = false;

	}


	public String getSatelliteName() {
		return satelliteName;
	}

	public File getDirectory() {
		return directory;
	}

	public boolean getIsVisible(){
		return isVisible;
	}



	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}


	public void addOrbit(){
		try {
			getLine();
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		//TODO enviar as 3 linhas do TLE
		try {
			this.orbit = new Orbit(line1,line2, line3);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvalidTleException e) {
			e.printStackTrace();
		} catch (SatNotFoundException e) {
			e.printStackTrace();
		}

	}

	public Orbit getOrbit() {
		return orbit;
	}



	public void getLine() throws IOException{
		File f = new File(directory.getAbsolutePath());
		String aux;
		FileReader fr = new FileReader(f);
		int i= 0;
		try {
			BufferedReader br = new BufferedReader(fr);
			while((aux=br.readLine())!=null){
				if(i==0)
					line1 = aux;
				if(i==1)					
					line2 = aux;
				else if(i==2)
					line3 = aux;
				i++;
			}
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public String toString(){
		return getSatelliteName();
	}

}
